<?php
/**
 * Created by PhpStorm.
 * User: kcswag
 * Date: 12/9/17
 * Time: 4:15 PM
 */

namespace AppBundle\Libs;


use Symfony\Component\Config\Definition\Exception\Exception;
use Symfony\Component\DependencyInjection\Container;

class PaymentCompany
{
    private $container;

    private $name;


    public function __construct(Container $container)
    {
        $this->container = $container;
        $this->getDefault();
    }


    public function getName(){
        return $this->name;
    }

    public function setName($name){
        $this->name = $name;
    }

    protected function getDefaultPaymentCompany(){
        return $this->container->getParameter('payment')['default'];
    }

    protected function getList(){
        return $this->container->getParameter('payment')['payment_list'];
    }

    protected function getDefault(){
        $company = $this->getDefaultPaymentCompany();
        $list = $this->getList();
        if(!in_array($company,$list)){
            throw new Exception("Invalid payment company {$company}!");
        }
        $this->setName($company);
        return $this->name;
    }


}